package org.mbds.android.sismapp.sensors;

/**
 * 
 * @author vlwb5512
 * This class will store the sensor data retrieved by SensorDataManager
 */
public class SensorData {
	
	public float[] val = null;
	public float[] filteredVal = null;
	public float[] orientation = null;
	public float[] rotation = null;
	public double norme = 0;
	public long time = 0;
	public double computedvAL = 0;
	public float yaw = 0;
	public float pitch = 0;
	public float roll = 0;
	public float[] fusedOrientation = null;
	
	public SensorData(long time, float[] values) {
		this.time = time;
		this.val = values;
		filteredVal=values.clone();
		norme = getNorme(val);
	}
	public void setComputedVal(float val) {
		computedvAL = val;
	}
	
	public void setOrientation(float[] orientation) { 
		this.orientation = orientation;
		yaw = (float) Math.toDegrees(orientation[0]);
		pitch = (float) Math.toDegrees(orientation[1]);
		roll = (float) Math.toDegrees(orientation[2]);
	}
	public void setFusedOrientation(float[] fusedOrientation) { 
		this.fusedOrientation = fusedOrientation;
		yaw = (float) Math.toDegrees(fusedOrientation[0]);
		pitch = (float) Math.toDegrees(fusedOrientation[1]);
		roll = (float) Math.toDegrees(fusedOrientation[2]);
	}
	public static double getNorme(float[] vector) {
		return Math.sqrt(Math.pow(vector[0],2)+Math.pow(vector[1],2)+Math.pow(vector[2],2));
	}	

	public static float[] sub(float[] vector1, float[] vector2) {
		float[] result = new float[3];
		result[0] = vector1[0]-vector2[0];
		result[1] = vector1[1]-vector2[1];
		result[2] = vector1[2]-vector2[2];
		return result;
	}	
	public static float[] add(float[] vector1, float[] vector2) {
		float[] result = new float[3];
		result[0] = vector1[0]+vector2[0];
		result[1] = vector1[1]+vector2[1];
		result[2] = vector1[2]+vector2[2];
		return result;
	}
}
